home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickTime / Programming Stuff / Documentation / develop articles / develop Issue 13 / Inside QuickTime and Components / GetQTImagePixelDepth / StdPix.c next >
Encoding:
C/C++ Source or Header  |  1997-02-26  |  5.3 KB  |  231 lines  |  [TEXT/KAHL]

  1. /****************************************************************************/
  2. /*                                                                            */
  3. /*    Application:    StdPix                                                    */
  4. /*                                                                            */
  5. /*    Files:            StdPix.π                                                */
  6. /*                    StdPix.π.rsrc                                            */
  7. /*                    StdPix.c                                                */
  8. /*                                                                            */
  9. /*    Programmer:        Edgar Lee                                                */
  10. /*    Organization:    Apple Computer, Inc.                                    */
  11. /*    Department:        Developer Technical Support, DTS                        */
  12. /*    Language:        C (Think C version 5.0.2)                                */
  13. /*    Date Created:    09-24-92                                                */
  14. /*                                                                            */
  15. /****************************************************************************/
  16.  
  17. #include <ImageCompression.h>
  18.  
  19. /* Constant Declarations */
  20.  
  21. #define    WWIDTH    170
  22. #define    WHEIGHT    145
  23.  
  24. #define WLEFT    (((screenBits.bounds.right - screenBits.bounds.left) - WWIDTH) / 2)
  25. #define WTOP    (((screenBits.bounds.bottom - screenBits.bounds.top) - WHEIGHT) / 2)
  26.  
  27. /* Global Variable Definitions */
  28.  
  29.  
  30. void initMac();
  31.  
  32. void createWindow();
  33. void doEventLoop();
  34.  
  35. void doBottleneckTest();
  36.  
  37. main()
  38. {
  39.     initMac();
  40.     
  41.     createWindow();
  42.     
  43.     doEventLoop();
  44. }
  45.  
  46. void initMac()
  47. {
  48.     MaxApplZone();
  49.  
  50.     InitGraf( &thePort );
  51.     InitFonts();
  52.     InitWindows();
  53.     InitMenus();
  54.     TEInit();
  55.     InitDialogs( nil );
  56.     InitCursor();
  57.     FlushEvents( 0, everyEvent );
  58. }
  59.  
  60. void createWindow()
  61. {
  62.     Rect        rect;
  63.     WindowPtr    window;
  64.     
  65.     SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
  66.     window = NewCWindow( 0L, &rect, "\pStdPix", true, documentProc,
  67.                             (WindowPtr)-1L, true, 0L );                        
  68.     SetPort( window );
  69.     
  70.     TextMode( srcCopy );
  71.     TextSize( 9 );
  72.     TextFont( geneva );
  73. }
  74.  
  75. void DrawDepth( short depth, int col, int row)
  76. {
  77.     MoveTo( col, row );
  78.     if (depth != -1)
  79.         switch(depth) {
  80.             case 1:
  81.                 DrawString("\pQuickTime 1-bit");
  82.                 break;
  83.             case 2:
  84.                 DrawString("\pQuickTime 2-bit");
  85.                 break;
  86.             case 4:
  87.                 DrawString("\pQuickTime 4-bit");
  88.                 break;
  89.             case 8:
  90.                 DrawString("\pQuickTime 8-bit");
  91.                 break;
  92.             case 16:
  93.                 DrawString("\pQuickTime 16-bit");
  94.                 break;
  95.             case 24:
  96.                 DrawString("\pQuickTime 24-bit");
  97.                 break;
  98.             case 32:
  99.                 DrawString("\pQuickTime 32-bit");
  100.                 break;
  101.             default:
  102.                 DrawString("\pQuickTime image");
  103.                 break;
  104.         }    
  105.     else
  106.         DrawString("\pQuickDraw image");
  107. }
  108.  
  109.  
  110.  
  111. short    gDepth = -1;
  112.  
  113. pascal void myStdPix( PixMapPtr src, Rect *srcRect, MatrixRecordPtr matrix,
  114.                         short mode, RgnHandle mask, PixMapPtr matte,
  115.                         Rect *matteRect, short flags )
  116. {
  117.     ImageDescriptionHandle        desc;
  118.     Ptr                            data;
  119.     long                        bufferSize;
  120.     
  121.     GetCompressedPixMapInfo( src, &desc, &data, &bufferSize, nil, nil );
  122.     gDepth = (**desc).depth;
  123. }
  124.  
  125. pascal void myTextProc( short byteCount, Ptr textBuf, Point numer, Point denom ){}
  126. pascal void myLineProc( Point newPt ){}
  127. pascal void myRectProc( GrafVerb verb, Rect *r ){}
  128. pascal void myRRectProc( GrafVerb verb, Rect *r, short ovalWidth, short ovalHeight ){}
  129. pascal void myOvalProc( GrafVerb verb, Rect *r ){}
  130. pascal void myArcProc( GrafVerb verb, Rect *r, short startAngle, short arcAngle ){}
  131. pascal void myPolyProc( GrafVerb verb, PolyHandle poly ){}
  132. pascal void myRgnProc( GrafVerb verb, RgnHandle rgn ){}
  133. pascal void myBitsProc( BitMap *bitPtr, Rect *srcRect, Rect *dstRect,
  134.                         short mode, RgnHandle maskRgn ){}
  135.  
  136.  
  137. void GetQTImagePixelDepth(PicHandle picture)
  138. {
  139.     CQDProcs    bottlenecks;
  140.  
  141.     /* Define our own bottlenecks. */
  142.     SetStdCProcs( &bottlenecks );
  143.     
  144.     bottlenecks.textProc    = (Ptr)myTextProc;
  145.     bottlenecks.lineProc    = (Ptr)myLineProc;
  146.     bottlenecks.rectProc    = (Ptr)myRectProc;
  147.     bottlenecks.rRectProc    = (Ptr)myRRectProc;
  148.     bottlenecks.ovalProc    = (Ptr)myOvalProc;
  149.     bottlenecks.arcProc        = (Ptr)myArcProc;
  150.     bottlenecks.polyProc    = (Ptr)myPolyProc;
  151.     bottlenecks.rgnProc        = (Ptr)myRgnProc;
  152.     bottlenecks.bitsProc    = (Ptr)myBitsProc;
  153.     bottlenecks.newProc1    = (Ptr)myStdPix;        /* pixProc */
  154.     
  155.     /* Install our custom bottlenecks to intercept any compressed images. */
  156.     (*(qd.thePort)).grafProcs = (QDProcs *)&bottlenecks;
  157.     DrawPicture( picture, &((**picture).picFrame) );
  158.          
  159.     /* Switch back to the default procs. */
  160.       (*(qd.thePort)).grafProcs = 0L;
  161. }
  162.  
  163. void doBottleneckTest()
  164. {
  165.     int            i;
  166.     PicHandle    picture;
  167.     Rect        rect;
  168.  
  169.     for (i = 0; i < CountResources( 'PICT' ); i++)
  170.         {
  171.         // Load picture
  172.         picture = (PicHandle)Get1IndResource( 'PICT', i + 1 );
  173.         
  174.         GetQTImagePixelDepth(picture);
  175.           
  176.           // Display picture
  177.         rect = (**picture).picFrame;
  178.         OffsetRect( &rect, -rect.left, -rect.top );
  179.         OffsetRect( &rect, 10, ((rect.bottom - rect.top) + 10) * i + 10 );
  180.         DrawPicture( picture, &rect );
  181.         
  182.         // Free any memory used by the picture.
  183.         ReleaseResource( picture );
  184.         
  185.         // Display the compression depth
  186.         DrawDepth( gDepth, rect.right + 10, rect.top + 10 );
  187.         gDepth = -1;
  188.         }
  189. }
  190.  
  191. void doEventLoop()
  192. {
  193.     EventRecord event;
  194.     WindowPtr   window;
  195.     short       clickArea;
  196.     Rect        screenRect;
  197.  
  198.     for (;;)
  199.     {
  200.         if (WaitNextEvent( everyEvent, &event, 0, nil ))
  201.         {
  202.             if (event.what == mouseDown)
  203.             {
  204.                 clickArea = FindWindow( event.where, &window );
  205.                 
  206.                 if (clickArea == inDrag)
  207.                 {
  208.                     screenRect = (**GetGrayRgn()).rgnBBox;
  209.                     DragWindow( window, event.where, &screenRect );
  210.                 }
  211.                 else if (clickArea == inContent)
  212.                 {
  213.                     if (window != FrontWindow())
  214.                         SelectWindow( window );
  215.                 }
  216.                 else if (clickArea == inGoAway)
  217.                     if (TrackGoAway( window, event.where ))
  218.                         return;
  219.             }
  220.             else if (event.what == updateEvt)
  221.             {
  222.                 window = (WindowPtr)event.message;    
  223.                 SetPort( window );
  224.                 
  225.                 BeginUpdate( window );
  226.                 doBottleneckTest();
  227.                 EndUpdate( window );
  228.             }
  229.         }
  230.     }
  231. }